<?php
/**
 * Error class
 */
class ZzERROR extends Exception
{
	public $classError;
	
  public function __construct($class, $message,$code = 0) {
    parent::__construct($message, $code);
		if(!is_null($class))
			$this->classError = 'on class '.get_class($class);
		else
			$this->classError = '';
		
		// Add the error on the log file
		$file = fopen('./Log/errors.log','a+');
		fwrite($file,date('Ymd H:i:s').' : '.$_SERVER['REQUEST_URI'].' : '.$_SERVER['HTTP_REFERER'].' : '.$this);
		fclose($file);
  }

  public function __toString() {
		if(!empty($this->code))
			$this->code = 'n°'.$this->code;
		else
			$this->code = '';
    return "Error {$this->code} {$this->classError} : {$this->message}\n";  }

}